package cn.wolfcode.crud.web.controller;

import cn.wolfcode.crud.qo.JsonResult;
import cn.wolfcode.crud.qo.QuerObjcet;
import cn.wolfcode.crud.service.IPermissionService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    protected IPermissionService apermission;

    //查询操作
    @RequiresPermissions(value = {"permission:list","查询权限"},logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QuerObjcet qo) {
        model.addAttribute("PageResult",  apermission.query(qo));
        return "permission/list";
    }

    //删除操作
    @RequiresPermissions(value = {"permission:delete","删除权限"},logical = Logical.OR)
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
            apermission.delete(id);
        }
        return "redirect:/permission/list";
    }

    //json发送
    @ResponseBody
    @RequestMapping("/reload")
    public JsonResult reload() {

            apermission.reload();
            return new JsonResult();

    }

}
